home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / undo / UndoableEditSupport.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  2.5 KB  |  82 lines

  1. package javax.swing.undo;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Vector;
  5. import javax.swing.event.UndoableEditEvent;
  6. import javax.swing.event.UndoableEditListener;
  7.  
  8. public class UndoableEditSupport {
  9.    protected int updateLevel;
  10.    protected CompoundEdit compoundEdit;
  11.    protected Vector listeners;
  12.    protected Object realSource;
  13.  
  14.    public UndoableEditSupport() {
  15.       this((Object)null);
  16.    }
  17.  
  18.    public UndoableEditSupport(Object var1) {
  19.       this.realSource = var1 == null ? this : var1;
  20.       this.updateLevel = 0;
  21.       this.compoundEdit = null;
  22.       this.listeners = new Vector();
  23.    }
  24.  
  25.    protected void _postEdit(UndoableEdit var1) {
  26.       UndoableEditEvent var2 = new UndoableEditEvent(this.realSource, var1);
  27.       Enumeration var3 = this.listeners.elements();
  28.  
  29.       while(var3.hasMoreElements()) {
  30.          ((UndoableEditListener)var3.nextElement()).undoableEditHappened(var2);
  31.       }
  32.  
  33.    }
  34.  
  35.    public synchronized void addUndoableEditListener(UndoableEditListener var1) {
  36.       this.listeners.addElement(var1);
  37.    }
  38.  
  39.    public synchronized void beginUpdate() {
  40.       if (this.updateLevel == 0) {
  41.          this.compoundEdit = this.createCompoundEdit();
  42.       }
  43.  
  44.       ++this.updateLevel;
  45.    }
  46.  
  47.    protected CompoundEdit createCompoundEdit() {
  48.       return new CompoundEdit();
  49.    }
  50.  
  51.    public synchronized void endUpdate() {
  52.       --this.updateLevel;
  53.       if (this.updateLevel == 0) {
  54.          this.compoundEdit.end();
  55.          this._postEdit(this.compoundEdit);
  56.          this.compoundEdit = null;
  57.       }
  58.  
  59.    }
  60.  
  61.    public int getUpdateLevel() {
  62.       return this.updateLevel;
  63.    }
  64.  
  65.    public synchronized void postEdit(UndoableEdit var1) {
  66.       if (this.updateLevel == 0) {
  67.          this._postEdit(var1);
  68.       } else {
  69.          this.compoundEdit.addEdit(var1);
  70.       }
  71.  
  72.    }
  73.  
  74.    public synchronized void removeUndoableEditListener(UndoableEditListener var1) {
  75.       this.listeners.removeElement(var1);
  76.    }
  77.  
  78.    public String toString() {
  79.       return super.toString() + " updateLevel: " + this.updateLevel + " listeners: " + this.listeners + " compoundEdit: " + this.compoundEdit;
  80.    }
  81. }
  82.